﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MouseExtender.Model;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Input;
using MouseExtender.Common;
using Tomers.WPF.Controls;

namespace MouseExtender.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        private ObservableCollection<LauncherItem> _items = null;
        private ActionCommand _launchItemCommand = null;

        public ObservableCollection<LauncherItem> Items
        {
            get
            {
                return _items;
            }
            set
            {
                if (_items != value)
                {
                    _items = value;
                    NotifyPropertyChanged("Items");
                }
            }

        }

        public ActionCommand LaunchItemCommand
        {
            get
            {
                return _launchItemCommand;
            }
            set
            {
                if (value != _launchItemCommand)
                {
                    _launchItemCommand = value;
                    NotifyPropertyChanged("LaunchItemCommand");
                }
            }
        }

        public MainViewModel()
        {
            Items = new ObservableCollection<LauncherItem>()
            {
                new LauncherItem()
                {
                    LaunchPath ="Item1",
                    ItemColor = Colors.Red,
                },
                new LauncherItem()
                {
                    LaunchPath ="Item2",
                    ItemColor = Colors.Blue,
                },
            };

            LaunchItemCommand = new ActionCommand();
            LaunchItemCommand.ExecuteDelegate = (p) =>
                {
                    var typedParameter = (EventCommandParameter<object, RoutedEventArgs>)p;
                    var element = (FrameworkElement)typedParameter.EventArgs.OriginalSource;
                    var launcherItem = (LauncherItem)element.DataContext;
                    MessageBox.Show(launcherItem.LaunchPath);
                };
        }
    }
}
